src="${pageContext.request.contextPath}/resources/script/jquery-3.1.1.min.js"
	

//验证帐号是否格式
$("#username").blur(function(){
	var username = $("#username").val();
	$.ajax({
		url : "usernameVerify",
		dataType : 'html',
		data : ({'username':username}),
		success : function(data) {
			if(data==0){
				$("#usernamediv").html("<font color='green'>用户名可以使用</font>")
			}else if(data==1){
				$("#usernamediv").html("<font color='red'>用户名已存在</font>")
			}else{
				$("#usernamediv").html("<font color='red'>用户名必须超过6位</font>")
			}
		}
	})
	});

//验证密码格式
$("#password").blur(function(){
	var password = $("#password").val();
	$.ajax({
		url : "password1Verify",
		dataType : 'html',
		data : ({'password1':password}),
		success : function(data) {
			if(data==0){
				$("#password1div").html("<font color='red'>密码必须超过6位</font>")
			}else if(data==1){
				$("#password1div").html("<font color='red'>危险</font>")
			}else if(data==2){
				$("#password1div").html("<font color='yellow'>一般</font>")
			}else{
				$("#password1div").html("<font color='green'>安全</font>")
			}
		}
	})
	});

//验证两次密码是否一致格式
$("#password2").blur(function(){
	var password2 = $("#password2").val();
	var password = $("#password").val();
	if(password==password2){
		$.ajax({
			url : "password2Verify",
			dataType : 'html',
			data : ({'password2':'0'}),
			success : function(data) {
				$("#password2div").html("<font color='green'>√</font>")
			}
		})
	}else{
		$.ajax({
			url : "password2Verify",
			dataType : 'html',
			data : ({'password2':'1'}),
			success : function(data) {
				$("#password2div").html("<font color='red'>两次密码不一致</font>")
			}
		})
	}
	});
//验证邮箱格式是否正确
$("#email").blur(function(){
	var email = $("#email").val();
	
	$.ajax({
		url : "emailVerify",
		dataType : 'html',
		data : ({'email':email}),
		success : function(data) {
			if(data==1){
				$("#emaildiv").html("<font color='red'>邮箱格式不正确</font>");
			}else{
				$("#emaildiv").html("<font color='green'>√</font>");
			}
		}
	})
	});

//验证码输入是否正确
$("#captcha").blur(function(){
	var captcha = $("#captcha").val();
	
	$.ajax({
		url : "codeVerify",
		dataType : 'html',
		data : ({'verifyCode':captcha}),
		success : function(data) {
			if(data==1){
				$("#captchadiv").html("<font color='red'>验证码输入不正确</font>");
			}else{
				$("#captchadiv").html("<font color='green'>√</font>");
			}
		}
	})
	});

$("#registerSubmit").click(function(){
	var url = "userRegister";
	var username = $("#username").val();
	var password = $("#password").val();
	var email = $("#email").val();
	var Uname = $("#Uname").val();
	var Usex = $("#Usex").val();
	var Uphone = $("#Uphone").val();
	var Uaddr = $("#Uaddr").val();
	
	$.ajax({
		url : url,
		dataType : 'html',
		data : ({"username":username,"password":password,"email":email,"Uname":Uname,"Usex":Usex,"Uphone":Uphone,"Uaddr":Uaddr}),
		success : function(data) {
			if(data==0){
				$("#XMB").html("<font color='green'>注册成功！</font><a href='toIndex'>点击返回首页</a>");
			}else if(data==1){
				$("#username")[0].focus();
			}else if(data==2){
				$("#password")[0].focus();
			}else if(data==3){
				$("#password2")[0].focus();
			}else if(data==4){
				$("#email")[0].focus();
			}else if(data==5){
				$("#captcha")[0].focus();
			}
		}
	})
});

function reloadValidateCode(){
    $("#validateCodeImg").attr("src","<%=basePath%>/validateCode.shtml?data=" + new Date() + Math.floor(Math.random()*24));
}